﻿namespace Gunningine
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// Core engine functions.
    /// </summary>
    public class GameStateScriptingCore
    {
        /// <summary>
        /// Log message.
        /// </summary>
        /// <param name="message"></param>
        public void LogDebug(string message)
        {
            Logger.Debug(message);
        }

        /// <summary>
        /// Log message.
        /// </summary>
        /// <param name="message"></param>
        public void LogInfo(string message)
        {
            Logger.Info(message);
        }

        /// <summary>
        /// Log message.
        /// </summary>
        /// <param name="message"></param>
        public void LogWarning(string message)
        {
            Logger.Warn(message);
        }

        /// <summary>
        /// Log message.
        /// </summary>
        /// <param name="message"></param>
        public void LogError(string message)
        {
            Logger.Error(message);
        }
    }

    /// <summary>
    /// Input functions
    /// </summary>
    public class GameStateScriptingInput
    {
        private InputManager inputMgr;

        private RenderSystem renderSystem;

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="renderSystem"></param>
        public GameStateScriptingInput(InputManager inputMgr, RenderSystem renderSystem)
        {
            this.inputMgr = inputMgr;
            this.renderSystem = renderSystem;
        }

        /// <summary>
        /// Is key currently down?
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public bool IsKeyDown(KeyCode key)
        {
            return this.inputMgr.IsKeyDown(key);
        }

        /// <summary>
        /// Is key depressed this frame?
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public bool IsKeyPressed(KeyCode key)
        {
            return this.inputMgr.IsKeyPressed(key);
        }

        /// <summary>
        /// Is key released this frame?
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public bool IsKeyReleased(KeyCode key)
        {
            return this.inputMgr.IsKeyReleased(key);
        }

        /// <summary>
        /// Mouse X position
        /// </summary>
        /// <returns></returns>
        public int MouseX
        {
            get { return this.inputMgr.MouseX; }
        }

        /// <summary>
        /// Mouse Y position
        /// </summary>
        /// <returns></returns>
        public int MouseY
        {
            get { return this.renderSystem.ScreenHeight - this.inputMgr.MouseY; }
        }
    }

    /// <summary>
    /// General graphics functions.
    /// </summary>
    public class GameStateScriptingGraphics
    {
        private RenderSystem renderSystem;

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="renderSystem"></param>
        public GameStateScriptingGraphics(RenderSystem renderSystem)
        {
            this.renderSystem = renderSystem;
        }

        /// <summary>
        /// Create a new render texture.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="channels"></param>
        public void CreateRenderTexture(string name, int width, int height, int channels)
        {
            this.renderSystem.CreateRenderTexture(name, width, height, channels);
        }
    }
}
